﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Othello_Game
{
    /// <summary>
    /// This class read the Weight vectors from a file
    /// </summary>
    public class WeightsReader
    {

        public WeightVector[] Weights;

        public void readWeights()
        {
            FileInfo file = new FileInfo("Weights.txt");
            FileStream FS = null;
            StreamReader SR = null;

            string[] weights = new string[5];
            char[] splitter = {',',' ',';'};
            double[] weights_array = new double[5];
            String weights_line = string.Empty;

            try
            {
                FS = File.OpenRead("Weights.txt");
                SR = new StreamReader(FS);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }

            this.Weights = new WeightVector[3];

            for (int i = 0; i < 3; i++)
            {
                weights_line = SR.ReadLine();
                weights = weights_line.Split(splitter);
                for (int j = 0; j < 5; j++)
                {
                    weights_array[j] = Convert.ToDouble(weights[j]);
                }
                Weights[i] = new WeightVector((double[]) weights_array.Clone());
            }

            FS.Close();
        }

    }
}
